<?php
/**
 * Create By: PhpStorm
 * User: niechenguang
 * File: Home.php
 * Date: 2016/11/27
 * Time: 23:48
 */

namespace app\home\controller;

use app\api\model\dao\UserAccount;
use app\api\model\dao\UserCoupon;
use app\api\model\page\goods\GetGoodsCategory;
use app\library\Common;
use app\library\CommonConfig;
use app\library\PageBase;
use think\Cookie;
use think\Request;
use think\Controller;

class Home extends Controller
{
    private $param;

    public function __construct()
    {
        parent::__construct();

        $this->param = Request::instance()->param();
    }

    /**
     * @DESC 首页
     */
    public function homepage()
    {
        //判断用户是否登录，登录进入首页，没登录跳转到登录页
        Cookie::set(CommonConfig::COOKIE_TYPE, Common::getToken());
        $check = new PageBase();
        $ret = $check->checkToken($this->param);
        if (false === $ret) {
            return $this->fetch('home/pages/login');
        }
        return $this->fetch('home/pages/index');
    }

    public function hometest()
    {
        //判断用户是否登录，登录进入首页，没登录跳转到登录页
        return $this->fetch('home/pages/test');
    }

    public function homeData()
    {
        $data = [
            'errno' => 0,
            'data' => [
                ['id' => '4', 'text' => 'P3'],
                ['id' => '5', 'text' => 'P4'],
                [
                    'text' => '二级',
                    'children' => [
                        ['id' => '6', 'text' => 'P6'],
                    ]
                ],
            ]
        ];
        $obj = new GetGoodsCategory();
        $catInfo = $obj->excute($this->param);
        foreach ($catInfo['data'] as $info) {
            $tmp[] = [
                'text' => $info['cat_name'],
                'id' => $info['cat_id'],
            ];
        }
        $catInfo['data'] = $tmp;
        return JSON($catInfo);
    }


    public function getUserInfo()
    {

        //$list = UserCoupon::where('status',1);
        //var_dump($list->currentPage());
        //$page = $list->render();
        //$this->assign('list', $list);
        //$this->assign('page', $page);
        return $this->fetch('home/pages/userinfo');

        /*
        $data['name'] = 'ThinkPHP';
        $data['email'] = 'thinkphp@qq.com';
        $this->assign('data',$data);
        return $this->fetch('home/pages/userinfo');
        */
    }


}